package com.itheima.springbootwebtlias.mapper;


import com.itheima.springbootwebtlias.pojo.Student;
import com.itheima.springbootwebtlias.pojo.StudentQueryParam;
import org.apache.ibatis.annotations.*;

import java.util.List;
import java.util.Map;

@Mapper
public interface StudentMapper {
    // 条件分页查询
    List<Student> list(StudentQueryParam studentQueryParam);

    // 添加学员
    @Insert("insert into student(name, no, gender, phone, id_card, is_college, address, degree, graduation_date, clazz_id, violation_count, violation_score, create_time, update_time) " +
            "values (#{name},#{no},#{gender},#{phone},#{idCard},#{isCollege},#{address},#{degree},#{graduationDate},#{clazzId},#{violationCount},#{violationScore},#{createTime},#{updateTime})")
    void insert(Student student);

    // 根据id查询学员
    @Select("select * from student where id = #{id};")
    Student getById(Integer id);

    // 修改学员信息
    @Update("update student set name = #{name}, no = #{no}, gender = #{gender}, phone = #{phone}, id_card = #{idCard}, is_college = #{isCollege}, address = #{address}, degree = #{degree}, graduation_date = #{graduationDate}, clazz_id = #{clazzId}, violation_count = #{violationCount}, violation_score = #{violationScore}, update_time = #{updateTime} where id = #{id}")
    void update(Student student);

    // 批量删除学员信息
    void deleteByIds( List<Integer> ids);

    /**
     * 统计班级学生人数
     */
    @MapKey("name")
    List<Map> countClassData();


    /**
     * 统计学生学历信息
     */
    @MapKey("value")
    List<Map> countStudentDegreeData();

    // 统计班级里有的学生人数
    @Select("select count(*) from student where clazz_id = #{id}")
    Integer isHasEmpByDeptId(Integer id);

    // 违纪分数处理
    @Update("update student set violation_count = violation_count + 1, violation_score = violation_score + #{score} where id = #{id}")
    void updateViolation(Integer id, Integer score);
}
